#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from typing import List
from pydantic import BaseModel, Field


class CopyMetaExtendInfo(BaseModel):
    database_name: str = Field(None, description="sqlserver数据库名称", alias="databaseName")
    first_lsn: str = Field(None, description="first_lsn", alias="firstLSN")
    last_lsn: str = Field(None, description="last_lsn", alias="lastLSN")
    checkpoint_lsn: str = Field(None, description="checkpoint_lsn", alias="CheckpointLSN")
    recovery_model: str = Field(None, description="数据库恢复模式", alias="recoveryModel")
    backup_path: str = Field(None, description="数据库备份路径", alias="backupPath")
    meta_path: str = Field(None, description="元数据备份路径", alias="MetaPath")
    backup_result: bool = Field(None, description="备份结果", alias="backupResult")
    begin_time: int = Field(None, description="备份开始时间", alias="beginTime")
    end_time: int = Field(None, description="备份完成时间", alias='endTime')
    backup_time: int = Field(None, description="备份时间", alias='backupTime')
    local_file_path: str = Field(None, description="数据库文件路径列表", alias="dbFilePath")
    version: str = Field(None, description="sqlserver版本")
    offset_to_utc: str = Field(None, description="和UTC的时差")
    meta_info: dict = dict()


class CopyMetaInfo(BaseModel):
    backup_type: str = Field(None, description="备份类型", alias="backupType")
    instance_name: str = Field(None, description="实例名", alias="instanceName")
    extend_info: List[CopyMetaExtendInfo] = Field(None, alias="extendInfo")


class RecoveryInfo(BaseModel):
    database_name: str = Field(None, description="数据库名称", alias="databaseName")
    recovery_model: str = Field(None, description="数据库恢复模式", alias="recoveryModel")


class ExtendInfo(BaseModel):
    # 副本查询接口对应extend_info
    version: str = Field(None, description="sqlserver版本")
    node_info: list = Field([], description="节点信息", alias="nodeInfo")
    replica_info: list = Field([], description="副本信息", alias="replicaInfo")
    database_list: list = Field([], description="数据库列表", alias="databaseList")
    begin_time: int = Field(None, description="备份开始时间", alias="beginTime")
    end_time: int = Field(None, description="备份完成时间", alias="endTime")
    backup_time: int = Field(None, description="备份时间", alias='backupTime')
    extend_info: List[RecoveryInfo] = Field([], description="恢复模式信息", alias="extendInfo")
    offset_to_utc: str = Field(None, description="和UTC的时差")
    meta_info: dict = dict()
